//
//  HWQuanBuView.m
//  HWanGame
//
//  Created by 陈道斌 on 2019/9/2.
//  Copyright © 2019 Chendaobin. All rights reserved.
//

#import "HWQuanBuView.h"
#import "QCScreeningCollectionViewCell.h"
//#import "HWFeileiModel.h"
//#import "HWFeileiModel.h"
#import "HWQCFeiLeiModel.h"

@interface HWQuanBuView()<UITableViewDataSource,UITableViewDelegate,UIGestureRecognizerDelegate>
@property(strong,nonatomic) UIView *grayView;
@property(strong,nonatomic) UIView *whiteView;
@property(strong,nonatomic) UITableView *mainaTableVie;
@property(strong,nonatomic) NSMutableArray   *dataMuArr;


@end

@implementation HWQuanBuView

-(UITableView *)mainaTableVie {
    
    if (_mainaTableVie == nil
        ) {
    
        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 1, kScreenW, 36*3) style:UITableViewStylePlain];
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        _mainaTableVie.backgroundColor = [UIColor whiteColor];
        
        
        
    }
    return   _mainaTableVie ;
}


//- (UICollectionView *)collectionView {
//
//    if (_collectionView == nil) {
//        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
//
//        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 1,kScreenW , 36*3) collectionViewLayout:layout];
//        _collectionView.delegate = self;
//        _collectionView.dataSource = self;
//        _collectionView.backgroundColor = [UIColor whiteColor];
//        // [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"MyCollectionViewCell"];
//
//
//        //   [UINib nibWithNibName:NSStringFromClass([QCScreeningCollectionViewCell class]) bundle:nil]
//
////        [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MyCollectionViewHeaderView"];
////        [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"MyCollectionViewFooterView"];
//        [_collectionView registerNib: [UINib nibWithNibName:NSStringFromClass([QCScreeningCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:@"MyCollectionViewCell"];
//
//
//    }
//
//
//    return  _collectionView;
//}


- (instancetype)initWithFrame:(CGRect)frame  {
    
    if (self  = [super initWithFrame:frame]) {
        
        [self adddatashuju];
        // 添加灰色背景
        [self addgrayView];
        
        [self setupUI];
        
        
    }
    return  self;
    
}


- (void)adddatashuju {
    
    
    NSArray *arr = @[@"全部平台",@"ios端",@"安卓端"];
     
     self.dataMuArr = [[NSMutableArray alloc]init];
     for (int i = 0; i < arr.count; i++) {
         
         HWQCFeiLeiModel *mode = [[HWQCFeiLeiModel alloc]init];
       //  HWQCFeiLeiModel
       //  mode.name =  arr[i];
         
         mode.name = [NSString stringWithFormat:@"%@",arr[i]];
          mode.xuanzhong = NO;
         if (i == 0) {
             mode.xuanzhong = YES;
         }
        [self.dataMuArr addObject:mode];
     }
     
    
}


//  设置UI
- (void)setupUI {
    
 

    self.whiteView = [[UIView alloc]init];
    self.whiteView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.whiteView];
    
    UIView *fengexianView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 1)];
    fengexianView.backgroundColor = RGB(215, 215, 215);
    //  fengexianView.backgroundColor = [UIColor orangeColor];
    [self.whiteView addSubview:fengexianView];
    
   // [self.whiteView addSubview:self.collectionView];
    [self.whiteView addSubview:self.mainaTableVie];
    
    
    
  
    //  全部分类
    UIButton *chongzhiBut = [UIButton buttonWithType:UIButtonTypeCustom];
    chongzhiBut.frame =   CGRectMake(0, 144-35, kScreenW/3, 35);
    chongzhiBut.backgroundColor = RGB(239, 236, 239);
    [chongzhiBut setTitleColor:RGB(102, 102, 102) forState:UIControlStateNormal];
    [chongzhiBut setTitle:@"重置" forState:UIControlStateNormal];
    chongzhiBut.titleLabel.font = [UIFont systemFontOfSize:12];
    [chongzhiBut addTarget:self action:@selector(chongtap) forControlEvents:UIControlEventTouchUpInside];
    [self.whiteView addSubview:chongzhiBut];

    UIButton *determineBut = [UIButton buttonWithType:UIButtonTypeCustom];
    determineBut.frame =   CGRectMake(kScreenW/3, 144-35, kScreenW/3*2, 35);
    determineBut.backgroundColor = RGB(54,147,253);
    [determineBut setTitleColor:RGB(255, 255, 255) forState:UIControlStateNormal];
    [determineBut setTitle:@"确定" forState:UIControlStateNormal];
    determineBut.titleLabel.font = [UIFont systemFontOfSize:12];
    [determineBut addTarget:self action:@selector(queding) forControlEvents:UIControlEventTouchUpInside];
    [self.whiteView addSubview:determineBut];
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}
- (void)relayoutTheChildControls {
    // self.whiteView.backgroundColor = [UIColor redColor];
    self.whiteView.frame = CGRectMake(0, self.whibackvieY, kScreenW, 36*4);
    self.grayView.frame = CGRectMake(0, self.whibackvieY+36*4, kScreenW, kScreenH-self.whibackvieY-36*4+10);
    
}






// 添加灰色View
-(void)addgrayView {
    
    self.grayView = [[UIView alloc]init];
    self.grayView.frame  = CGRectMake(0,300, 400, 400);
    
    self.grayView.backgroundColor =  RGB(51, 51, 51);
    self.grayView.alpha = 0.6;
    [self addSubview:self.grayView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapView:)];
    //  tap.delegate = self;
    [self.grayView addGestureRecognizer:tap];
    
    
    
    
}

- (void)tapView:(UITapGestureRecognizer *)touch {
    
    [touch.view.superview removeFromSuperview];
    //   [[NSNotificationCenter defaultCenter] postNotificationName:@"notifyName1" object:nil];
    
    
}


#pragma mark --------   点击一些按钮操作
// 点击重置按钮
- (void)chongtap {
    
    DLog(@"重置按钮");
    [self adddatashuju];
    [self.mainaTableVie reloadData];
    
}

// 点击确定按钮

- (void)queding {
    
    
    DLog(@"确定");
    
    for (int i = 0; i < self.dataMuArr.count; i++) {
         HWQCFeiLeiModel *mode =  self.dataMuArr[i];
        if (mode.xuanzhong) {
            [self.delagete HWQuanBuViewXuantap:i];
            
        }
    }
    
    [self removeFromSuperview];
    
    
    
}



#pragma mark  ---------- UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return  self.dataMuArr.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *cellID = @"cellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.selectionStyle  =UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor whiteColor];
    
    UILabel *miaoshulabel1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 36)];
    miaoshulabel1.textAlignment = NSTextAlignmentCenter;
    miaoshulabel1.textColor = RGB(51, 51, 51);
    miaoshulabel1.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:miaoshulabel1];
    
     HWQCFeiLeiModel *mode =  self.dataMuArr[indexPath.row];
     miaoshulabel1.text = [NSString stringWithFormat:@"%@",mode.name];
    
    if (mode.xuanzhong) {
        miaoshulabel1.textColor = RGB(54, 147, 253);
    } else {
        
         miaoshulabel1.textColor = RGB(51, 51, 51);
    }
     UIView *fengexianView  = [[UIView alloc]initWithFrame:CGRectMake(0, 35, kScreenW, 1)];
    fengexianView.backgroundColor = RGB(232, 232, 242);
    [cell.contentView addSubview:fengexianView];
    
    
    
    return  cell;
    
    
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    return  36;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
      for (int i = 0; i < self.dataMuArr.count; i++) {
          HWQCFeiLeiModel *mode =  self.dataMuArr[i];
          mode.xuanzhong = NO;
          
     }
    
      HWQCFeiLeiModel *mode =  self.dataMuArr[indexPath.row];
       mode.xuanzhong = YES;
      [self.mainaTableVie reloadData];
    
    
}









@end



//#import "HWQuanBuView.h"
//#import "QCScreeningCollectionViewCell.h"
////#import "HWFeileiModel.h"
////#import "HWFeileiModel.h"
//#import "HWQCFeiLeiModel.h"
//
//@interface HWQuanBuView()<UICollectionViewDelegate,UICollectionViewDataSource,UIGestureRecognizerDelegate>
//@property(strong,nonatomic) UIView *grayView;
//@property(strong,nonatomic) UIView *whiteView;
//@property(strong,nonatomic) UITableView *mainaTableVie;
//@property(strong,nonatomic) UICollectionView *collectionView;
//@property(strong,nonatomic) NSMutableArray   *dataMuArr;
//@end
//
//@implementation HWQuanBuView
//
//
//- (UICollectionView *)collectionView {
//
//    if (_collectionView == nil) {
//        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
//
//        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 1,kScreenW , 36*3) collectionViewLayout:layout];
//        _collectionView.delegate = self;
//        _collectionView.dataSource = self;
//        _collectionView.backgroundColor = [UIColor whiteColor];
//        // [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"MyCollectionViewCell"];
//
//
//        //   [UINib nibWithNibName:NSStringFromClass([QCScreeningCollectionViewCell class]) bundle:nil]
//
////        [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MyCollectionViewHeaderView"];
////        [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"MyCollectionViewFooterView"];
//        [_collectionView registerNib: [UINib nibWithNibName:NSStringFromClass([QCScreeningCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:@"MyCollectionViewCell"];
//
//
//    }
//
//
//    return  _collectionView;
//}
//
//
//- (instancetype)initWithFrame:(CGRect)frame  {
//
//    if (self  = [super initWithFrame:frame]) {
//        // 添加灰色背景
//        [self addgrayView];
//
//        [self setupUI];
//
//
//    }
//    return  self;
//
//}
//
//
////  设置UI
//- (void)setupUI {
//
//    self.dataMuArr = [[NSMutableArray alloc]init];
//    for (int i = 0; i < 30; i++) {
//
//        HWQCFeiLeiModel *mode = [[HWQCFeiLeiModel alloc]init];
//      //  HWQCFeiLeiModel
//        mode.name = @"精选";
//        mode.xuanzhong = NO;
//       [self.dataMuArr addObject:mode];
//
//
//    }
//
//
//
//    self.whiteView = [[UIView alloc]init];
//    self.whiteView.backgroundColor = [UIColor whiteColor];
//    [self addSubview:self.whiteView];
//
//    UIView *fengexianView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 1)];
//    fengexianView.backgroundColor = RGB(215, 215, 215);
//    //  fengexianView.backgroundColor = [UIColor orangeColor];
//    [self.whiteView addSubview:fengexianView];
//
//    [self.whiteView addSubview:self.collectionView];
//
//
//    //  全部分类
//    UIButton *chongzhiBut = [UIButton buttonWithType:UIButtonTypeCustom];
//    chongzhiBut.frame =   CGRectMake(0, 144-35, kScreenW/3, 35);
//    chongzhiBut.backgroundColor = RGB(239, 236, 239);
//    [chongzhiBut setTitleColor:RGB(102, 102, 102) forState:UIControlStateNormal];
//    [chongzhiBut setTitle:@"重置" forState:UIControlStateNormal];
//    chongzhiBut.titleLabel.font = [UIFont systemFontOfSize:12];
//    [chongzhiBut addTarget:self action:@selector(chongtap) forControlEvents:UIControlEventTouchUpInside];
//    [self.whiteView addSubview:chongzhiBut];
//
//    UIButton *determineBut = [UIButton buttonWithType:UIButtonTypeCustom];
//    determineBut.frame =   CGRectMake(kScreenW/3, 144-35, kScreenW/3*2, 35);
//    determineBut.backgroundColor = RGB(54,147,253);
//    [determineBut setTitleColor:RGB(255, 255, 255) forState:UIControlStateNormal];
//    [determineBut setTitle:@"确定" forState:UIControlStateNormal];
//    determineBut.titleLabel.font = [UIFont systemFontOfSize:12];
//    [determineBut addTarget:self action:@selector(queding) forControlEvents:UIControlEventTouchUpInside];
//    [self.whiteView addSubview:determineBut];
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//}
//- (void)relayoutTheChildControls {
//    // self.whiteView.backgroundColor = [UIColor redColor];
//    self.whiteView.frame = CGRectMake(0, self.whibackvieY, kScreenW, 36*4);
//    self.grayView.frame = CGRectMake(0, self.whibackvieY+36*4, kScreenW, kScreenH-self.whibackvieY-36*4+10);
//
//}
//
//
//
//
//
//
//// 添加灰色View
//-(void)addgrayView {
//
//    self.grayView = [[UIView alloc]init];
//    self.grayView.frame  = CGRectMake(0,300, 400, 400);
//
//    self.grayView.backgroundColor =  RGB(51, 51, 51);
//    self.grayView.alpha = 0.6;
//    [self addSubview:self.grayView];
//
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapView:)];
//    //  tap.delegate = self;
//    [self.grayView addGestureRecognizer:tap];
//
//
//
//
//}
//
//- (void)tapView:(UITapGestureRecognizer *)touch {
//
//    [touch.view.superview removeFromSuperview];
//    //   [[NSNotificationCenter defaultCenter] postNotificationName:@"notifyName1" object:nil];
//
//
//}
//
//
//#pragma mark --------   点击一些按钮操作
//// 点击重置按钮
//- (void)chongtap {
//
//    DLog(@"重置按钮");
//
//}
//
//// 点击确定按钮
//
//- (void)queding {
//
//
//    DLog(@"确定");
//}
//
//
//
//
/////**每个分区item的个数 */
//- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
//    return self.dataMuArr.count;
//}
///**
// 创建cell
// */
//- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
//    static NSString *cellIdentifier = @"MyCollectionViewCell";
//    QCScreeningCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
//    //   cell.backgroundColor = [UIColor  orangeColor];
//   // cell.backgroundColor = RGB(240, 240, 240);
//
//
//    cell.yudingButton.layer.cornerRadius = 5;
//    cell.yudingButton.layer.masksToBounds = YES;
//
//    cell.yudingButton.backgroundColor = RGB(245, 245, 245);
//
//    HWQCFeiLeiModel *model  =   self.dataMuArr[indexPath.row];
//
//    if (model.xuanzhong) {
//
//
//        cell.yudingButton.backgroundColor = RGB(54, 147, 253);
//        [cell.yudingButton setTitleColor:RGB(255 , 255  ,255) forState:UIControlStateNormal];
//
//    } else {
//
//        cell.yudingButton.backgroundColor = RGB(245, 245, 245);
//        [cell.yudingButton setTitleColor:RGB(51, 51, 51) forState:UIControlStateNormal];
//
//
//    }
//    // cell.imageStr = _imagesArray[indexPath.item];
//    return cell;
//
//}
//
///**
// 点击某个cell
// */
//- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
//   // QCScreeningCollectionViewCell *cell = (QCScreeningCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
//
//    for (int i = 0; i < self.dataMuArr.count; i++) {
//         HWQCFeiLeiModel *model  =   self.dataMuArr[i];
//          model.xuanzhong = NO;
//    }
//    HWQCFeiLeiModel *model  =   self.dataMuArr[indexPath.row];
//    model.xuanzhong = YES;
//    [self.collectionView reloadData];
//
//
//
//    NSLog(@"点击了第%ld分item",(long)indexPath.item);
//
//
//
//}
///**
// cell的大小
// */
//- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
//    CGFloat cellW = (kScreenW-30-15*3)/4;
//
//    return CGSizeMake(cellW, 36);
//}
//
///**
// 分区内cell之间的最小行间距
// */
//- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
//    return 0;
//}
//
//- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
//    return UIEdgeInsetsMake(0, 15, 0, 15);
//
//
//
//
//}
//
//
//@end
